﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Ink_Canvas.Windows
{
    /// <summary>
    /// Window5.xaml 的交互逻辑
    /// </summary>
    public partial class Window5 : Window
    {
        private ProgressBar progressBar;

        // 创建一个定时器
        private DispatcherTimer timer;
        // 创建一个进度值变量
        private int progress;

        public Window5()
        {
            InitializeComponent();
            // 初始化进度条控件
            progressBar = this.FindName("ProgressBar") as ProgressBar;
            progressBar.Minimum = 0;
            progressBar.Maximum = 100;
            progressBar.Value = 0;
            progressBar.Width = 200;
            progressBar.Height = 50;

            // 将进度条控件添加到窗口中
            ProgressBar = progressBar;

            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(0.2);

            // 设置定时器的触发事件
            timer.Tick += Timer_Tick;

            // 初始化进度值
            progress = 0;

            // 启动定时器
            timer.Start();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            // 增加进度值
            progress += 5;

            // 更新进度条的值
            progressBar.Value = progress;

            // 如果进度值达到100，停止定时器
            if (progress == 100)
            {
                timer.Stop();
                // 创建一个MainWindow的实例
                MainWindow mainWindow = new MainWindow();

                // 显示MainWindow
                mainWindow.Show();

                // 关闭本窗口
                this.Close();
            }
        }
    }
}
